import 'package:flutter/material.dart';
import 'package:flutterDemo/common_ui/navigation/navigation_bar_widget.dart';
import 'package:flutterDemo/pages/home/home_page.dart';
import 'package:flutterDemo/pages/hot_key/hot_key_page.dart';
import 'package:flutterDemo/pages/knowledge/knowledge_page.dart';
import 'package:flutterDemo/pages/personal/personal_page.dart';

class TabPage extends StatefulWidget {
  const TabPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return _TabPageState();
  }
}

class _TabPageState extends State<TabPage> {
  int currentIndex = 0; //当前页面的索引
  late List<Widget> pages; // 页面列表
  late List<String> labels; // 标签列表
  late List<Widget> icons; // 切换前图标列表
  late List<Widget> activeIcons; // 切换后图标列表
  void initTabData() {
    // 初始化数据
    pages = [
      const HomePage(),
      const HotKeyPage(),
      KnowledgePage(),
      const PersonalPage(),
    ];
    labels = ["首页", "热榜", "知识", "我的"];
    icons = [
      Image.asset(
        "assets/images/icon_home_grey.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_hot_key_grey.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_knowledge_grey.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_personal_grey.png",
        width: 30,
        height: 30,
      ),
    ];
    activeIcons = [
      Image.asset(
        "assets/images/icon_home_selected.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_hot_key_selected.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_knowledge_selected.png",
        width: 30,
        height: 30,
      ),
      Image.asset(
        "assets/images/icon_personal_selected.png",
        width: 30,
        height: 30,
      ),
    ];
  }

  @override
  void initState() {
    super.initState();
    initTabData();
  }

  @override
  Widget build(BuildContext context) {
    return NavigationBarWidget(
        pages: pages,
        labels: labels,
        icons: icons,
        activeIcons: activeIcons,
        onTapChange: (index) {
          print("index:$index");
        });
  }
}
